
#include "mapStreet.hpp"
#include "../config/config.hpp"
#include <math.h>

MapStreet::MapStreet(Edge *e, Graph *g)
{
	this->edge = e;
	this->setId(this->edge->getId());
	this->setMapElementType(STREET);
	
	Node *nodeTemp = NULL;
	
	nodeTemp = g->getNode(this->edge->getOriginId());
	this->setIntersectionOriginPositionX(nodeTemp->getPositionX());
	this->setIntersectionOriginPositionY(nodeTemp->getPositionY());
	this->setPositionX(nodeTemp->getPositionX());
	this->setPositionY(nodeTemp->getPositionY());
	
	nodeTemp = g->getNode(this->edge->getDestinyId());
	this->setIntersectionDestinyPositionX(nodeTemp->getPositionX());
	this->setIntersectionDestinyPositionY(nodeTemp->getPositionY());

	int xOPos = this->getIntersectionOriginPositionX();
	int yOPos = this->getIntersectionOriginPositionY();
	int xDPos = this->getIntersectionDestinyPositionX();
	int yDPos = this->getIntersectionDestinyPositionY();

	int width = xOPos - xDPos;
	if(width < 0)
		width*= (-1);

	int height = yOPos - yDPos;
	if(height < 0)
		height*= (-1);

	std::string source;
	RoadType type = this->edge->getRoadType();
	switch(type){
		case CALLE:
			source = Config::getInstance()->get("street_image_source");
			break;

		case AVENIDA:
			source = Config::getInstance()->get("avenue_image_source");
			break;

		case AUTOPISTA:
			source = Config::getInstance()->get("highway_image_source");
			break;

		default:
			source = Config::getInstance()->get("street_image_source");

	}

    this->setImageSource(source);
	this->setImageWidth(width);
	this->setImageHeight(height);
	
	this->inclination = atan2((double)(xOPos - xDPos),(double)(yOPos - yDPos));

	nodeTemp = NULL;
}

MapStreet::MapStreet(std::string id)
{
	this->setId(id);
	this->setMapElementType(STREET);
}

int MapStreet::getIntersectionOriginPositionX()
{
	return this->nodeOriginPositionX;
}

int MapStreet::getIntersectionOriginPositionY()
{
	return this->nodeOriginPositionY;
}

int MapStreet::getIntersectionDestinyPositionX()
{
	return this->nodeDestinyPositionX;
}

int MapStreet::getIntersectionDestinyPositionY()
{
	return this->nodeDestinyPositionY;
}

void MapStreet::setIntersectionOriginPositionX(int x)
{
	this->nodeOriginPositionX = x;
}

void MapStreet::setIntersectionOriginPositionY(int y)
{
	this->nodeOriginPositionY = y;
}

void MapStreet::setIntersectionDestinyPositionX(int x)
{
	this->nodeDestinyPositionX = x;
}

void MapStreet::setIntersectionDestinyPositionY(int y)
{
	this->nodeDestinyPositionY = y;
}

double MapStreet::getInclination()
{
	return this->inclination;
}

int MapStreet::getInitialHeight()
{
	return this->edge->getInitialHeight();
}

int MapStreet::getFinalHeight()
{
	return this->edge->getFinalHeight();
}

int MapStreet::getInitialMPHeight()
{
	return this->edge->getInitialMPHeight();
}

int MapStreet::getFinalMPHeight()
{
	return this->edge->getFinalMPHeight();
}

bool MapStreet::belongToMP()
{
	return this->edge->getBelongToMP();
}